'use strict';
const db = uniCloud.database()
const coll = db.collection('fenshu')
const coll1 = db.collection('kaiguan')
exports.main = async (event, context) => {

	let res0 = await coll1.where({
		_id: 'b751f28065af72790838fc190f8961c7'
	}).get()
	console.log('ssssssssss', res0)
	if (res0.data[0].kaiguan == 0) {
		return {
			status: 0,
			msg: '当前时段不允许投票'
		}
	} else {
		let res = await coll.where({
			deviceId: event.deviceId,
		}).count()
		console.log('查询数量', res)
		if (res.total > 0) {
			let res1 = await coll.where({
				deviceId: event.deviceId,
			}).update({
				fen: event.fen
			})
			return {
				status: 1,
				msg: '成功!'
			}
		} else {
			let res2 = coll.add({
				flag: 'flag',
				deviceId: event.deviceId,
				fen: event.fen
			})
			return {
				status: 1,
				msg: '成功!'
			}
		}
	}








};